{include file="public/header" $title="基本资料" /}
<style>
    #editBox{
        width: 400px;display: none;
    }
</style>
</header>
<body>
    <form class="layui-form" action="" style="height: 100%;margin-top: 30px">
        <div class="layui-inline layui-form-item">
            <label class="layui-form-label">角色</label>
            <div class="layui-input-inline">
                <input type="text" name="role" lay-verify="title|required" value="{$adminInfo.role}" autocomplete="off" disabled class="layui-input" maxlength="16">
            </div>
            <div class="layui-form-mid layui-word-aux">角色不可修改</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input type="text" name="username" lay-verify="title|required" value="{$adminInfo.username}" autocomplete="off" placeholder="请输入账号：6-12位字母数字集合" class="layui-input" maxlength="16">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>

            <div class="layui-input-inline">
                <div class="layui-upload">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="portraitLink" src="__HOSTURI__{$adminInfo.portrait}">
                        <p id="demoText"></p>
                    </div>
                    <button type="button" class="layui-btn" id="portrait">上传图片</button>
                </div>
                <input type="hidden" name="portrait" lay-verify="portrait" value="{$adminInfo.portrait}" autocomplete="off"  class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="name"  value="{$adminInfo.name}" maxlength="16" autocomplete="off" placeholder="请输入姓名" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" lay-verify="phone" value="{$adminInfo.phone}" autocomplete="off" placeholder="请输入手机号" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" lay-verifu="email" value="{$adminInfo.email}" autocomplete="off" placeholder="请输入邮箱" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="status" lay-skin="switch" lay-text="ON|OFF" id="status">
                <script>
                    var status = "{$adminInfo.status}";
                    if(status == 1)
                    {
                        $("#status").attr("checked",true)
                    }else{
                        $("#status").attr("checked",false)
                    }
                </script>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="gosub" type="button">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

<!--弹框结束-->
</body>
<script>
    layui.use(['upload','form'], function(){
        var upload = layui.upload;
        var form = layui.form;


        //文件上传
        var uploadInst = upload.render({
            elem: '#portrait'
            ,url: "{:url('nadmin/upload/uploadOne?from=portrait')}"
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#portraitLink').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){

                layer.msg(res.msg);
                if(res.status == 0){
                    //如果上传失败
                }else{
                    $('[name="portrait"]').val(res.data);
                    $('#demoText').children().remove();
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

        //编辑操作
        form.on('submit(gosub)',function(data){

            if(data.field.status == 'on'){
                data.field.status = 1;
            }else{
                data.field.status = 0;
            }

            $.post("{:url('nadmin/personage/updateBaseDate')}",data.field,function(datas){
                layer.msg(datas.msg,{time:1000});

            },'json')
        })


    });
</script>
</html>